package com.jike.shop.cloud.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Configuration
@MapperScan("com.jike.shop.cloud.mapper")
public class WebConfig {

    @Component
    public static class CreateTimeAndUpdateTimeHandler implements MetaObjectHandler {

        @Override
        public void insertFill(MetaObject metaObject) {
            setFieldValByName("createTime", LocalDateTime.now(), metaObject);
            setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
        }

        @Override
        public void updateFill(MetaObject metaObject) {
            setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
        }
    }
}
